package com.ea.dingtalk.api.controller;

import com.common.framework.web.response.ResultModel;
import com.ea.dingtalk.service.DingTalkIntegrateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName DingTalkController
 * @Description TODO
 * @Author XIONG CAI
 * @Date 2024/11/12
 */
@RestController
@RequestMapping("api/dingtalk/")
public class DingTalkController {
    @Autowired
    private DingTalkIntegrateService dingTalkIntegrateService;

    /**
     * 获取钉钉getAccessToken
     * @return
     */
    @RequestMapping("getAccessToken")
    public ResultModel getAccessToken(){
        String accessToken = dingTalkIntegrateService.getAccessToken();
        return ResultModel.success(accessToken);
    }

    /**
     * 根据用户code获取用户信息
     * @param code
     * @return
     */
    @GetMapping("getUserInfo/{code}")
    public ResultModel getUserInfo(@PathVariable("code") String code){
        Map<String, Object> userInfo = dingTalkIntegrateService.getUserInfo(code);
        return ResultModel.success(userInfo);
    }



}
